x=int(input())
M=0
if 999<x<10000:
    x1=x
    x2=x//10
    x3=x//100
    x4=x//1000
    x5=x%1000
    x6=x%1000//10
    x7=x%1000//100
    x8=x%100
    x9=x%100//10
    x10=x%10
    s=[x1,x2,x3,x4,x5,x6,x7,x8,x9,10]
    for y in s:
        k=0
        for i in range(1,y//2+1):
            if y%i==0:
                k+=1
        if k==1:
            M=max(M,y)
    print(M)
else:
    print("0")

